home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 441 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  51 lines

  1. Newsgroups: comp.lang.c++
  2. Path: ncrgw2.ncr.com!ncrhub2!lznj2!lziss3!ucseng!news
  3. From: Bill Himmelstoss <whimmel@ucs.att.com>
  4. Subject: Virtual functions and BC452
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <30EBDABA.7DE1@ucs.att.com>
  7. Sender: news@ucseng.ucs.att.com
  8. Content-Transfer-Encoding: 7bit
  9. Organization: AT&T Universal Card Services
  10. Mime-Version: 1.0
  11. Date: Thu, 4 Jan 1996 13:48:42 GMT
  12. X-Mailer: Mozilla 2.0b3 (Win95; I)
  13.  
  14. Hi!  I'm porting some Borland Pascal code to C++ and am having trouble with virtual functions. 
  15.  This stuff works great in BP, but not in BC.  Here's an example:
  16.  
  17. class Base {
  18.   public:
  19.     Base() {}
  20.   protected:
  21.     void cheeky();
  22.     virtual void monkey();
  23. };
  24.  
  25. void cheeky() {
  26.     monkey();
  27. }
  28.  
  29. class Derived: public Base {
  30.   protected:
  31.     virtual void monkey();
  32. }
  33.  
  34. ...
  35.  
  36. Derived d;
  37. d.cheeky();
  38.  
  39. This Base::cheeky() is calling Base::monkey() instead of Derived::monkey().  Why?  
  40.  
  41. Ok, now for the ringer:  It works properly under Turbo Debugger!
  42.  
  43. Billl
  44.  
  45.  
  46. -- 
  47. -----------------------------------------------------------
  48. Bill Himmelstoss         whimmel@ucs.att.com
  49. #include <std\disclaimer.h>  Developer, AT&T Universal Card
  50. -----------------------------------------------------------
  51.